/*
 * File name: 7250.c
 *
 * Description: It is part of 7250 protocol declared file
 *
 * Copyright (C) 2009, Beijing THHT Technology Co.,Ltd.
 *
 * Date         Modification            Name
 * ----------------------------------------------
 * 2009-05-25   Create                  Libo Jiao
 */

#include <stdlib.h>
#include <stdio.h>

#include "7250.h"

static float prod_to_float(const char *prod, int n)
{
    float f;

    return f;
}

static char* float_to_prod(float f, char *prod)
{
    int i, n = 8;
    char buf[9];
    
    snprintf(buf, 9, "%03.4f", f);

    for (i=0;i<9;i++)
        printf("%c ", buf[i]);

    printf("\n");

    for (i=0;i<10;i++) {
        prod[i*n+0] = buf[0]; 
        prod[i*n+1] = buf[1]; 
        prod[i*n+2] = buf[2]; 
        prod[i*n+3] = buf[3]; 
        prod[i*n+4] = buf[4]; 
        prod[i*n+5] = buf[5]; 
        prod[i*n+6] = buf[6]; 
        prod[i*n+7] = buf[7];
    }


    return prod;
}

static float inte_to_float(const char *inte, int n)
{
    float f;

    return f;
}

static char* float_to_inte(float f, char* inte)
{
    int i, n = 8;
    char buf[9];
    
    snprintf(buf, 9, "%03.4f", f);

    printf ("%s, buf = %s\n", __FUNCTION__, buf);
    for (i=0;i<1;i++) {
        inte[i*n+0] = buf[0]; 
        inte[i*n+1] = buf[1]; 
        inte[i*n+2] = buf[2]; 
        inte[i*n+3] = buf[3]; 
        inte[i*n+4] = buf[4]; 
        inte[i*n+5] = buf[5]; 
        inte[i*n+6] = buf[6]; 
        inte[i*n+7] = buf[7];
    }

    return inte;
}

static float temp_to_float(const char *temp, int n)
{
    float f;

    return f;
}

static char* float_to_temp(float f, char *temp)
{
    int i;
    char buf[6];

    snprintf(buf, 6, "%+02.1f", f);

    printf ("%s, buf = %s\n", __FUNCTION__, buf);
    for (i=0;i<5;i++) {
        temp[i*5+0] = buf[0];    
        temp[i*5+1] = buf[1];    
        temp[i*5+2] = buf[2];    
        temp[i*5+3] = buf[3];    
        temp[i*5+4] = buf[4];    
    }

    return temp;
}


char* tt_get_7250_string(char* str, float oil, float water, float temp)
{
    printf ("data = %s, oil = %f, water = %f, temp = %f\n", str, oil, water, temp);
    str[0] = '<';
    str[1] = ',';


    float_to_prod(oil, &str[2]);
    float_to_inte(water, &str[92]);
    float_to_temp(temp, &str[101]);

    str[131] = 1;
    str[132] = 2;

    str[133] = '1';

    return 0;
}
